package com.itheima.springboot_23_mail.service.impl;

import com.itheima.springboot_23_mail.service.SendMailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

//@Service //为了测试impl2,把这个注释掉
public class SendMailServiceImpl implements SendMailService {

    @Autowired //从配置文件中获取sendmail的配置
    private JavaMailSender javaMailSender;

    private String from="1320910060@qq.com";
    private String to="1320910060@qq.com";
    private String subject="test主题";
    private String context="test内容";

    @Override
    public void sendMail() {
        SimpleMailMessage simpleMailMessage=new SimpleMailMessage();
        simpleMailMessage.setFrom(from+"(22222)");
        simpleMailMessage.setTo(to);
        simpleMailMessage.setSubject(subject);
        simpleMailMessage.setText(context);
        javaMailSender.send(simpleMailMessage);
    }
}
